package cn.xfdzx.android.apps.shop.activity.procurement;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.ProcurementInfoBeen;
import cn.xfdzx.android.apps.shop.contract.ProcurementInfoContract;
import cn.xfdzx.android.apps.shop.presenter.ProcurementInfoPresenter;
import cn.xfdzx.android.apps.shop.util.Util;
import cn.xfdzx.android.apps.shop.util.Utils;

public class ProcurementHomeActivity extends BaseMvpActivity<ProcurementInfoPresenter> implements ProcurementInfoContract.View {

    @BindView(R.id.tv_dinggou)
    TextView tvDinggou;
    @BindView(R.id.tv_qingdan)
    TextView tvQingdan;
    @BindView(R.id.tv_shuoming)
    TextView tvShuoming;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.iv_banner)
    ImageView ivBanner;
    RoundedCorners roundedCorners;
    RequestOptions options;
    String phone;

    @Override
    public int getLayoutId() {
        return R.layout.activity_procurement_home;
    }

    @Override
    public void initView() {
        mPresenter = new ProcurementInfoPresenter();
        mPresenter.attachView(this);
        mPresenter.procurementInfo();

        roundedCorners = new RoundedCorners(4);
        options = RequestOptions.bitmapTransform(roundedCorners);
//        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
//                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
//                .error(R.drawable.icon_defult);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onProcurementInfoSuccess(ProcurementInfoBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Glide.with(this).load(bean.getData().getImage_path()).apply(options.transform(new CenterCrop(), roundedCorners)).into(ivBanner);
            phone = bean.getData().getPhone();
            tvName.setText("采购经理：" + bean.getData().getName());
            tvPhone.setText("Tel:" + bean.getData().getPhone());

        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    Intent intent;

    @OnClick({R.id.iv_back, R.id.tv_dinggou, R.id.tv_phone, R.id.tv_qingdan})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_phone:
                if (null != phone) {
                    Utils.callPhone(this, phone);
                }
                break;
            case R.id.iv_back:    //返回按钮点击
                finish();
                break;
            case R.id.tv_dinggou:    //
                intent = new Intent(this, ProcurementTypeListActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_qingdan:    //
                intent = new Intent(this, MyListingActivity.class);
                startActivity(intent);
                break;

        }
    }
}
